<?php
if (!defined('IN_IA')) {
    exit('Access Denied');
}
if (checksubmit('submit')) {
	if(empty($_GP["reserve-area"]) or empty($_GP["realname"]) or empty($_GP["getto-flight"]) or empty($_GP["getto-date"]) or empty($_GP["people-num"]) or empty($_FILES['wechat-image']['tmp_name'])){
		message("请填写必填选项");	
		exit;
	}
    if(!is_numeric($_GP['people-num'])){
        message("此行人数不为数字"); 
        exit;
    }
    if(!empty($_GP["packet-num"]) and !is_numeric($_GP['packet-num'])){
        message("行李数不为数字");
        exit;
    }
	$openid = get_sysopenid(true);
	$memberinfo = get_member_info($openid);
	if (!empty($_FILES['wechat-image']['tmp_name'])) {
        $upload = file_upload($_FILES['wechat-image']);
        if (is_error($upload)) {
            message($upload['message'], '', 'error');
        }
        
      	$wechat_image=ATTACHMENT_ROOT.$upload['path'];
    }
	if (!empty($_FILES['hotel-image']['tmp_name'])) {
    
        $upload = file_upload($_FILES['hotel-image']);
        if (is_error($upload)) {
            message($upload['message'], '', 'error');
        }
        
      	$hotel_image=ATTACHMENT_ROOT.$upload['path'];
    } 
    $insert_array = array(
    	'uid' => $memberinfo["id"],
    	'reserve_time' => date("Y-m-d H:i:s"),
    	'reserve_area' => $_GP["reserve-area"],
    	'people_num' => $_GP["people-num"],
    	'wechat_image' => $wechat_image,
    	'realname' => $_GP["realname"],
    	'getto_flight' => $_GP["getto-flight"],
    	'getto_date' => join(' ',explode('T', $_GP["getto-date"])),
    	'hotel' => $_GP["hotel"],
        'hotel_image' => $hotel_image,
        'packet_num' => $_GP["packet-num"],
    	'setoff_flight' => $_GP["setoff-flight"],
    	'remark' => $_GP["remark"],
    	'isread' => 0
    	);
    if(!empty($_GP["setoff-date"])){
        $setoff_date = join(' ',explode('T', $_GP["setoff-date"]));
        $insert_array['setoff_date'] = $setoff_date;
    }
    pdo_insert('eshop_member_reservation',$insert_array);
    message('申请提交成功！', create_url('mobile',array('act'=>'shopwap','do'=>'reservation_list')), 'success');
}
include page('reservation');
?>